package com.baweiwei.goodapi.dao;

import com.baweiwei.common.entity.Good;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

public interface GoodDao  extends JpaRepository<Good,Integer>, JpaSpecificationExecutor<Good> {


    @Modifying(clearAutomatically=true)
    @Transactional
    @Query(value = "update bw_good set g_kuncun=g_kuncun-?2 where g_id=?1 and g_kuncun>=?2",nativeQuery = true)
    int updateKuncun(Integer goodId,Integer num);

}
